import * as THREE from "three"
import renderOrderEnum from "../enum/renderOrder.enum"
import Chunk from "../other/321-8511"

const j = new THREE.Vector3(0, 0, 0),
  H = new THREE.Vector3(100, 100, 100),
  Y = new THREE.Vector3(),
  X = new THREE.Vector3(),
  J = new THREE.Box3()
export default class FallbackMesh extends THREE.Mesh<THREE.BoxBufferGeometry, THREE.MeshBasicMaterial> {
  bounds: THREE.Box3
  chunk: Chunk

  constructor() {
    super()
    this.bounds = new THREE.Box3()
    this.geometry = new THREE.BoxBufferGeometry(1, 1, 1)
    this.geometry.computeBoundingBox()
    this.geometry.computeBoundingSphere()
    this.chunk = new Chunk(-1, -1, this.geometry)
    const e = (e: THREE.MeshBasicMaterial) => {
      this.material = e
      this.material.side = THREE.BackSide
      this.material.transparent = !0
      this.material.depthWrite = !1
    }
    this.chunk.notifyOnMaterialUpdated(e)
    e(this.chunk.material)
    this.name = "FallbackMesh"
    this.renderOrder = renderOrderEnum.boundingSkybox
    this.setFromCenterAndSize(j, H)
  }
  setBounds(e) {
    if (this.bounds.equals(e)) return
    this.bounds.copy(e)
    const t = e.getSize(Y)
    this.position.copy(e.getCenter(X)), this.scale.set(t.x, t.y, t.z), this.updateMatrixWorld(!0)
  }
  setFromCenterAndSize(e, t = H) {
    this.setBounds(J.setFromCenterAndSize(e, t))
  }
}
